module diansha {
    /**
     * 泡泡类工厂
     * 减少对象的频繁创建，优化内存使用
     */
    export class paopao_factory {
        private static D: paopao_factory = null;
        private arr: Array<diansha.paopao> = new Array<diansha.paopao>()//泡泡工厂存储间(进来的都是可用的,未被用的)
        private out: paopao;
        private min: number = 200
        private max: number = 600

        constructor() {
            for (let i = 0; i < this.min; i++) {
                this.arr.push(new diansha.paopao())
            }
        }
        /**
         * 获取一个可用的对象
         */
        public get(shuzi: shuzi, startpoint: egret.Point, endpoint: egret.Point, time: number, errdetail: string, startcall: any, endcall: any): paopao {
            if (this.arr.length != 0) {
                this.out = this.arr.shift();
                this.out.shuzi = shuzi;
                this.out.startpoint = startpoint;
                this.out.endpoint = endpoint;
                this.out.errdetail = errdetail;
                this.out.startcall = startcall;
                this.out.endcall = endcall;
                this.out.time = time;
            } else {
                this.out = new paopao(shuzi, startpoint, endpoint, time, startcall, endcall)
            }


            if (this.arr.length <= this.min) {
                this.arr.push(new paopao(shuzi, startpoint, endpoint, time, startcall, endcall));
            }
            return this.out;
        }
        /**
         * 返还对象，回收再次利用
         */
        public give(paopao: paopao) {
            if (this.arr.length < this.max) {
                this.arr.push(paopao)
            }

        }
        /**
         * 返回实例确保单例
         */
        public static getinstance(): paopao_factory {
            if (this.D == null) {
                this.D = new paopao_factory();
            }
            return this.D;
        }
    }
}